var kfid="";
var rkwclist = new Array();
$(document).ready(function(){
	getUserRight();
	//日期函数
	$('.dateInput').datetimepicker({
			format: 'yyyy-mm-dd',
	        forceParse: 0,
	        todayBtn:  1,
	        autoclose: 1,
	        todayHighlight: 1,
	        minView: 2,
	        bootcssVer:3
	});	 
	$('.dateInput').datetimepicker('setStartDate', '1900-01-01');
	var endDate = new Date();
	$('.dateInput').datetimepicker('setEndDate', endDate);	
	$("input[name=rkqrsj]").val(nowDate());
	$("#functionNav").attr("href",navAddr);
	//获取并填充来源类型
	var lylxJson = ajaxResult("get",false,ProjectName+"/sysmanage.getIdAndNameInJb.do",{'tableName':'jb_lyfs'});
	loadSelect("#form1 select[name=lylx]",lylxJson.rows,'id','name');
	
	//获取并填充库房
	var kfJson = ajaxResult("get",false,ProjectName+"/sysmanage.getkfIdNameBybgyId.do",{'bgyId':userInfo.userid});
	if(kfJson.rows.length>0){
		var result="";		
		$.each(kfJson.rows,function(index,content){
			result +="<option value="+content["kfid"]+">"+content["kfmc"]+"</option>";
		})
		$("#form1 select[name=szkf]").html(result);
		//loadSelect("#form1 select[name=szkf]",kfJson.rows,'kfid','kfmc');
		//$("#form1 select[name=szkf] option[index='0']").remove(); 
	}else{
		alertFunc("您名下没有对应库房，请联系管理员为您分配库房！");
		window.location.href = "../query/zongZhangList.html";
	}
	
	
	//获取并填充时代
	getSdOption();
	//var doms_sd = ["DJH_SD1","DJH_SD2","DJH_SD3","DJH_SD4"];
	//selectFour(url_nd,doms_sd);
	
	//获取Url中的参数
	//var cpid =GetQueryString("id");
	//kfid =GetQueryString("szkf");
	//$("#form1 input[name=szkf]").val(kfid);
	//获取查询条件
	var params =$("#form1").serializeObject();
	
	
//初始化待入库Table
  	createTable('#dbTable',ProjectName+'/colmanage.getDbCpList.do','id',tblColTitle,params);  
  	//点击查询按钮
	 $("#search_btn").click(function(){
		 refreshTable('#dbTable','#form1');
	 });
	//点击查询按钮
	 $("#clear_btn").click(function(){
		 $("#rkdj_btn").show();
		 $("#refpkf_btn").show();
		 $('#dbTable').bootstrapTable('destroy');	
		 var params =$("#form1").serializeObject();
		 createTable('#dbTable',ProjectName+'/colmanage.getDbCpList.do','id',tblColTitle,params);  
	 });	 
	 //打印凭证
	 $("#dypz_btn").click(function(){
		 var params = "";
		 //var ztbz = $("input[name=ztbz]").val();
		 //if(ztbz==4){			 
//			 $("#dbTable input[name='btSelectItem']:checkbox").each(function(){ 
//				 if ("checked" == $(this).attr("checked")) { 
//					 ids+=$(this).attr('value')+",";
//				 } 
//			 }); 
/*			 params = "kfid="+kfid+"&userid="+userInfo.userid;
		 }else if(ztbz==5){*/
			 var ids = "";
			 var ids=selDataIds('#dbTable');
			/* $.each(rkwclist,function(index,value){
				 ids+=value+",";
			 });*/
			 if(ids.length == 0){
				 //alertFunc("请选择记录！");
				 //return false;
				 params = "kfid="+kfid+"&userid="+userInfo.userid;
			 }else{
				 params = "id="+ids;
			 }
			/* else
				 ids = ids.substring(0,ids.length-1);*/
		 //}

		 window.location.href=ProjectName+"/colmanage.createRkpz.do?"+params;
	 });
	 
	 //inittable(5);
})

	 

function inittable(ztbz){
	if(ztbz==4){
		$("#rkdj_btn").show();
		$("#refpkf_btn").show();
		var params =$("#form1").serializeObject();
		$('#dbTable').bootstrapTable('destroy');	
		createTable('#dbTable',ProjectName+'/colmanage.getDbCpList.do','id',tblColTitle,params);  
	}else{
		$("#rkdj_btn").hide();
		$("#refpkf_btn").hide();
		var rkwcstr = $("#rkwclist").val();
		if(rkwcstr!=""){			
			$.each(rkwcstr.split(","),function(index,value){
				rkwclist.push(value);
			});
		}
		var params =$("#form1").serializeObject();
		params["rkbgqrrid1"] = userInfo.userid;
		$('#dbTable').bootstrapTable('destroy');	
		createTable('#dbTable',ProjectName+'/colmanage.getDbCpList.do','id',tblColTitle,params);  
	}
	
}

function Addrkwclist(obj,id){
	if(!obj.checked){
		rkwclist.pop(id);
		$("#rkwclist").val(rkwclist.toString());
	}else{
		rkwclist.push(id);
		$("#rkwclist").val(rkwclist.toString());
	}
}

var tblColTitle = [{
	field: 'check',
	 checkbox:true	 
    }, {
        field: 'zdjh',
        title: '总登记号'
    },{
	        field: 'cpmc',
	        title: '藏品名称',
	        formatter: function(value, row, index) {	
	        	var result="";	  
    			if(row.sdbz==1 && row.sdrid == userInfo.userid)	   
        			result = '<a href="dbDetail.html?id='+row.id+'">'+value+'</a>';
    			else
    				result =value;
	        	return result;		        	
		      }
	    }, {
	        field: 'sd4',
	        title: '时代',
	        formatter: function(value, row, index) {
	        	var sd="";
	        	if(row.sd4!="" && row.sd4!=null){
	        		sd =row.sd4;
	        	}else if(row.sd3!="" && row.sd3!=null){
	        		sd =row.sd3;
	        	}else if(row.sd2!="" && row.sd2!=null){
	        		sd =row.sd2;
	        	}else if(row.sd1!="" && row.sd1!=null){
	        		sd =row.sd1;
	        	}
	        	return sd;
		      }
	    }, {
	        field: 'sjsl',
	        title: '实际数量',
	        formatter: function(value, row, index) {	        	
	        	return value+row.sjsldw;
		      }
	    }, {
	        field: 'lylxmc',
	        title: '来源方式'
	    }, {
	        field: 'szkf',
	        title: '库房'
	    },{
	        field: 'fw',
	        title: '方位'
	    }];
